import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class CommonTag extends StatelessWidget {
  final String title;
  final Color color;
  final Color backgroundColor;
  const CommonTag.ori(this.title,
      {Key key, this.color = Colors.black, this.backgroundColor = Colors.grey})
      : super(key: key);

  factory CommonTag(String title) {
    switch (title) {
      case '近地铁':
        return CommonTag.ori(
          title,
          color: Colors.blue,
          backgroundColor: Colors.blue[50],
        );
        break;
      case '集中供暖':
        return CommonTag.ori(
          title,
          color: Colors.green,
          backgroundColor: Colors.green[50],
        );
        break;
      case '新上':
        return CommonTag.ori(
          title,
          color: Colors.yellow,
          backgroundColor: Colors.yellow[50],
        );
        break;
      default:
        return CommonTag.ori(
          title,
          color: Colors.red,
          backgroundColor: Colors.red[50],
        );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(right: 4),
      padding: EdgeInsets.only(left: 4, right: 4, top: 2),
      decoration: BoxDecoration(
          color: backgroundColor, borderRadius: BorderRadius.circular(8)),
      child: Text(
        title,
      ),
    );
  }
}
